<?php get_instance()->view('common/header');?>
<style>
    .content-btn-box,.content-box{margin-top:10px;}
    .container {
        width: 100%;
    }
    .add-tag-btn{line-height: 40px;}
    .option-item {
        margin-bottom: 5px;
        position: relative;
    }
    .del-tag-btn{font-size: 14px;line-height: 36px;display: block;margin-bottom: 4px;}
    .del-tag-btn a{color: red;}
</style>
<div class="page-container home">
    <?php get_instance()->view('common/sidebar');?>
    <div class="page-content-wrapper">
        <div class="page-content">
            <div class="row">
                <div class="col-md-12">
                    <!-- BEGIN PAGE TITLE & BREADCRUMB-->
                    <h3 class="page-title"> <?php echo $title;?></h3>
                    <ul class="page-breadcrumb breadcrumb">
                        <li class="btn-group"> <a class="btn default ml_5 return" href="<?php echo getUrl('mall/home');?>"><i class="fa fa-chevron-left"></i> 返回</a> </li>
                        <li><a href="<?php echo getUrl('mall/home');?>">积分礼品列表 </a><i class="fa fa-angle-right"></i></li>
                        <li><a href="javascript:void(0);"><?php echo $add ? '添加' : '编辑';?>礼品</a></li>
                    </ul>
                    <!-- END PAGE TITLE & BREADCRUMB-->
                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <!-- BEGIN VALIDATION STATES-->
                    <div class="portlet box">
                        <div class="portlet-body form">
                            <!-- BEGIN FORM-->
                            <form action="<?php echo getUrl('mall/home/save')?>" class="form-horizontal" method="post" id="main-form" novalidate="novalidate">
                                <div class="form-body">
                                    <div class="form-group">
                                        <label class="control-label col-md-2">封面图<span class="required">*</span></label>
                                        <div class="col-md-6">
                                            <div class="fileinput fileinput-new" data-provides="fileinput"><input type="hidden">
                                                <div class="fileinput-preview thumbnail" data-trigger="fileinput" style="width: 200px; height: 150px; line-height: 140px;">
                                                    <img src="<?php echo ! $add ? $info['imgurl'] : getDefaultImg();?>" />
                                                </div>
                                                <div>
                                                    <span class="btn default btn-file">
                                                        <span class="fileinput-new">选择图片</span>
                                                            <span class="fileinput-exists">改变</span>
                                                        <input name="portrait" type="file">
                                                    </span>
                                                    <a href="#" class="btn default fileinput-exists" data-dismiss="fileinput">删除</a>
                                                </div>
                                            </div>
                                            <div class="clearfix margin-top-10">
                                                <span>
                                    <i class="fa fa-exclamation-triangle"></i>
                                </span>
                                                图片格式：gif,png,jpg;大小:2MB
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-2">标题<span class="required">*</span></label>
                                        <div class="col-md-6">
                                            <input class="form-control required" name="title" type="text" value="<?php echo ! $add ? $info['title'] : '';?>">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-2">积分<span class="required">*</span></label>
                                        <div class="col-md-6">
                                            <input class="form-control required" name="integral" type="text" value="<?php echo ! $add ? $info['integral'] : '';?>">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-md-2">产品须知<span class="required">*</span></label>
                                        <div class="col-md-6">
                                            <textarea  class="form-control required" name="notice" ><?php echo ! $add ? $info['notice'] : ''?></textarea>
                                        </div>
                                    </div>
                                    <!-- 商品描述 -->
                         			<div class="form-group">
                                        <label class="control-label col-md-2">产品介绍<span class="required">*</span></label>
                                        <div class="col-md-6">
                                         	<script  id="introduce" name="introduce" type="text/plain"><?php echo ! $add ? $info['introduce'] : ''?></script>  
                                        </div>
                                    </div>
                                    
                                    <div class="form-group">
							             <label class="control-label col-md-2">轮播图片</label>
							               <div class="col-md-9">
											<!--dom结构部分-->
											<div id="uploader-demo" class="wu-example">
												<!--用来存放item-->
												<div id="fileList" class="uploader-list">
												<?php if( ! $add){ foreach (json_decode($info['showurl'],true) as $k=>$v){?>
													<div id="WU_<?php echo $k?>"
														class="file-item thumbnail upload-state-done" style="">
														<img src="<?php echo getImage($v,'og');?>" >
														<div class="info"><?php $tA = explode('/', $v);echo $tA[count($tA)-1]?></div>
														<div class="info"
															style="top: 4px; text-indent: 0px; right: 4px; left: none;">
															<span style="float: right;" class="btna"><i
																class="fa fa-remove fa-2x"></i></span>
														</div>
														<input type="hidden" name="images[WU_<?php echo $k?>]" value="<?php echo $v;?>">
													</div>
													<?php }}?>
												</div>
												<div id="filePicker">选择图片</div>
											</div>
										</div>
										
							        </div>
                                    <div class="form-actionsc fluid">
                                        <div class="col-md-offset-2 col-md-9" style="padding-left: 0;">
                                            <input name="id" value="<?php echo ! $add ? $info['id'] : '';?>" type="hidden">
                                            <button class="btn green"><i class="fa fa-save"></i> 保存</button>
                                            <a class="btn default seach-btn" href="<?php echo getUrl('member/consumer');?>"><i class="fa fa-chevron-left"></i> 返回</a>
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                    <!-- END VALIDATION STATES-->
                </div>
                <!-- END PAGE CONTENT-->
            </div>
        </div>
    </div>
</div>
<div class="content-box" type="0" index="0">
    <script index="0" id="" name="free_content[]" type="text/plain"></script>
</div>
<script>
			$(function(){
				
				// 初始化Web Uploader
				var uploader = WebUploader.create({

				    // 选完文件后，是否自动上传。
				    auto: true,

				    // swf文件路径
				    //swf: '<?php echo $this->staticUrl;?>plugins/webuploader/Uploader.swf',

				    // 文件接收服务端。
				    server: '<?php echo getUrl('mall/home/uploadImge')?>',

				    // 选择文件的按钮。可选。
				    // 内部根据当前运行是创建，可能是input元素，也可能是flash.
				    pick: '#filePicker',

				    // 只允许选择图片文件。
				    accept: {
				        title: 'Images',
				        extensions: 'gif,jpg,jpeg,bmp,png',
				        mimeTypes: 'image/*'
				    },
					fileVal:'Filedata',
				});

				// 当有文件添加进来的时候
				var input = []
				uploader.on( 'fileQueued', function( file ) {
				    var $li = $(
				            '<div id="' + file.id + '" class="file-item thumbnail" style="">' +
				                '<img>' +
				                '<div class="info">' + file.name + '</div>' +
				                '<div class="info" style="top: 4px;text-indent: 0px;right: 4px;left: none;"><span style="float: right;" class="btna"><i class="fa fa-remove fa-2x"></i></span></div>' +
				                '<input type="hidden" name="images[]" value="">' +
					           '</div>'
				            ),
				    $img = $li.find('img');
				    input[file.id] = $li.find('input');
				    // $list为容器jQuery实例
				    $('#fileList').append( $li );

				    // 创建缩略图
				    // 如果为非图片文件，可以不用调用此方法。
				    // thumbnailWidth x thumbnailHeight 为 100 x 100
				    uploader.makeThumb( file, function( error, src ) {
				        if ( error ) {
				            $img.replaceWith('<span>不能预览</span>');
				            return;
				        }
				        $img.attr( 'src', src );
				    }, 100, 100 );
				});

				// 文件上传过程中创建进度条实时显示。
				uploader.on( 'uploadProgress', function( file, percentage ) {
				    var $li = $( '#'+file.id ),
				        $percent = $li.find('.progress span');
				    // 避免重复创建
				    if ( !$percent.length ) {
				        $percent = $('<p class="progress"><span></span></p>')
				                .appendTo( $li )
				                .find('span');
				    }
				    $percent.css( 'width', percentage * 100 + '%' );
				});

				// 文件上传成功，给item添加成功class, 用样式标记上传成功。
				uploader.on( 'uploadSuccess', function( file,data ) {
				    if(1){
				    	$( '#'+file.id ).addClass('upload-state-done');
					    input[file.id].val(data._raw);
				    }else{
					    var $li = $( '#'+file.id ),
				        $error = $li.find('div.error');
					    // 避免重复创建
					    if ( !$error.length ) {
					        $error = $('<div class="error"></div>').appendTo( $li );
					    }
					    //input[file.id].remove()
					    $error.text('上传失败');
				    }
				    												    
				});

				// 文件上传失败，显示上传出错。
				uploader.on( 'uploadError', function( file ) {
				    var $li = $( '#'+file.id ),
				        $error = $li.find('div.error');

				    // 避免重复创建
				    if ( !$error.length ) {
				        $error = $('<div class="error"></div>').appendTo( $li );
				    }

				    $error.text('上传失败');
				});

				// 完成上传完了，成功或者失败，先删除进度条。
				uploader.on( 'uploadComplete', function( file ) {
				    $( '#'+file.id ).find('.progress').remove();
				});

				//删除图片
				$(".btna").live('click',function(){
					$(this).parents(".file-item").remove();
					uploader.reset();
				})

				$('select[name="sub_class_id"]').select2();
				var model = $('#save-modal');
					
				 
				$('.remark').live('click', function(){
					model.find('.modal-title').html('评语');
					model.find('.has-error').removeClass('has-error').find('.validate_message').remove();
					model.find('.show_message_error').remove();

					model.find('input[name="credit"]').val('');
					model.find('input[name="comment"]').val('');
					model.find('input[name="online_id"]').val($(this).attr('onlineid'));
					model.find('input[name="student_id"]').val($(this).attr('studentid'));
					
					model.modal();
					
				});	

				$('#save-modal').on('shown.bs.modal', function (e) {
					uploader.refresh();
				})

				$.e_validate.init('#save-category-form',{modal:model,ignore:''});
			})
			
			</script>
<script type="text/javascript">
    $(function(){
        $.e_validate.init('#main-form', {});

        UE.getEditor('introduce',{
        	serverUrl:"<?php echo getUrl('mall/home/editor')?>",
            toolbars: [[
            'fullscreen', 'source', '|', 'undo', 'redo', '|',
            'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
            'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
            'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
            'directionalityltr', 'directionalityrtl', 'indent', '|',
            'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
            'link', 'unlink', 'anchor', '|','emotion', 'scrawl','attachment', 'insertcode','pagebreak', 'template', 'background', '|',
            'horizontal', 'date', 'time','simpleupload', 'spechars','|',
            'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols'
        ]],autoHeightEnabled:false,initialFrameWidth:'100%',initialFrameHeight:'300'});
    });
</script>
</body>
</html>